#pragma once
#include <cybertron/core/Log.hpp>
#include <cybertron/core/UtilRecordHelper.hpp>
#include "cybertron/node/TrafficActorHotArea.hpp"
#include <vector>
#include <string>
#include <fstream>

CYBERTRON_BEGIN

class RecordParser {

public:
	RecordParser();
	~RecordParser();
	virtual bool parse(std::string path, std::string output);
	static long long getNow();
protected:
	void parseOneMsg();
	void writeOneLine();
	std::fstream mRecordStream;
	std::fstream mOutputStream;
	std::uint64_t mTotalSize;
	std::uint64_t mParsedSize;
	std::uint64_t mParsePrecent;
	size_t mDumpPercent;
	Message mMsg;
	std::vector<std::string> mLineStrs;
	std::string mCommaStr;
	std::string mReturnStr;	
	std::map<int, TrafficActorHotArea> mHotAreas;

	void onFromAnyCreateHotArea();
	void onFromAnyUpdateHotArea();
	void onFromAnyDeleteHotArea();
	void onFromAnyAddDeleteTrafficActors();
	void onFromAnyUpdateTrafficActorPositionRotation();
	void onFromAnyUpdateTrafficActorFlags();
	void onFromAnyUpdateTrafficActorCustomProperties();

	void pushFrameStatus();
	struct ActorData
	{
		TrafficActor actor;
		std::vector<unsigned char> privateData;
		bool valid = false;
	};
	std::vector<std::vector<ActorData>> mHistoryDatas;
	std::map<int, int>mMainVehicleMap;
	std::map<int, int>mActorIdMap;
	std::vector<int>mActorIdVec;
	int mCurrentFrame;
	int mMaxActorId;
	virtual void dumpHistory();
	int mFps;
};

CYBERTRON_END